package com.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.qiniu.common.QiniuException;
import com.service.IIssueCommentService;
import com.service.IIssueService;
import com.service.ILabelService;
import io.swagger.annotations.*;
import living.com.result.ApiResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *     后台请求处理
 * </p>
 * @author 大忽悠
 * @create 2022/2/20 11:35
 */
@RestController
@RequestMapping("/manager")
@Api(tags = "后台请求处理")
@RequiredArgsConstructor
public class ManagerController {
    private final IIssueService iIssueService;
    private final IIssueCommentService iIssueCommentService;
    private final ILabelService iLabelService;

    @ApiOperation("获取未审核的问题")
    @GetMapping("/unAuditIssues")
    public ApiResult<Map<String,Object>> getUnauditIssue( @ApiParam("起始页")@RequestParam Integer startPage,
                                                          @ApiParam("一页多少条数据")@RequestParam Integer pageSize) throws JsonProcessingException {
        return ApiResult.success(iIssueService.getUnauditIssue(startPage,pageSize));
    }

    @ApiOperation("问题通过审核")
    @PostMapping("/passIssue")
    public ApiResult<Boolean> passIssue(@RequestParam@ApiParam("问题id") Integer issue_id)
    {
         return ApiResult.success(iIssueService.passIssue(issue_id));
    }

    @ApiOperation("逻辑删除问题")
    @DeleteMapping("/logicDelIssue")
    public ApiResult<Boolean> logicDelTargetQuestion(@ApiParam("问题id")@RequestParam Integer issue_id,
                                                     @ApiParam("原因")@RequestParam String reason) throws QiniuException {
        return ApiResult.success(iIssueService.backLogicDelIssue(issue_id,reason));
    }


    @ApiOperation("获取未审核的回答")
    @GetMapping("/unAuditComments")
    public ApiResult<Map<String,Object>> getUnauditComment( @ApiParam("起始页")@RequestParam Integer startPage,
                                                          @ApiParam("一页多少条数据")@RequestParam Integer pageSize) throws JsonProcessingException {
        return ApiResult.success(iIssueCommentService.getUnauditComment(startPage,pageSize));
    }

    @ApiOperation("回答通过审核")
    @PostMapping("/passComment")
    public ApiResult<Boolean> passComment(@RequestParam@ApiParam("回答id") Integer comment_id)
    {
        return ApiResult.success(iIssueCommentService.passComment(comment_id));
    }

    @ApiOperation("逻辑删除指定回答")
    @DeleteMapping("/logicDelComment")
    public ApiResult<Boolean> logicDelTargetComment(@ApiParam("回答id")@RequestParam Integer comment_id,
                                                    @ApiParam("原因")@RequestParam String reason ) throws QiniuException {
        Boolean res=iIssueCommentService.backLogicDel(comment_id,reason);
        return ApiResult.success(res);
    }

    @ApiOperation("获取未审核的标签")
    @GetMapping("/unAuditLabels")
    public ApiResult<Map<String,Object>> getUnAuditLabels( @ApiParam("起始页")@RequestParam Integer startPage,
                                                            @ApiParam("一页多少条数据")@RequestParam Integer pageSize)
    {
        return ApiResult.success(iLabelService.getUnAuditLabels(startPage,pageSize));
    }

    @ApiOperation("标签通过审核")
    @PostMapping("/passLabel")
    public ApiResult<Boolean> passLabel(@RequestParam@ApiParam("标签id") Integer label_id)
    {
        return ApiResult.success(iLabelService.passLabel(label_id));
    }

    @ApiOperation("删除指定标签")
    @DeleteMapping("/logicDelLabel")
    public ApiResult<Boolean> logicDelLabel(@RequestParam@ApiParam("标签id") Integer label_id) throws QiniuException {
        Boolean res=iLabelService.delTargetLabel(label_id);
        return ApiResult.success(res);
    }
}
